package com.gethb.data.prod.asfservice.impl;

import java.util.HashMap;
import java.util.List;
import com.gethb.pub.utils.KLineDataUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import com.gethb.data.mdo.KlinesDo;


//@Configuration      //1.主要用于标记配置类，兼备Component的效果。
//@EnableScheduling   // 2.开启定时任务
public class CallKLineServiceImpl {

    private static final Logger LOG = LoggerFactory.getLogger(CallKLineServiceImpl.class);


//    @Async
//    @Scheduled(fixedDelay = 60000) // 间隔1秒
//    public void getKLineData() throws InterruptedException {
//        getKLineData("btcusdt");
//        getKLineData("ethbtc");
//    }

//   private void getKLineData(String symbol) throws InterruptedException {
//       List<KlinesDo> list = KLineDataUtils.requestList(symbol, "1min", 1);
//       HashMap<Long,KlinesDo> map = KLineDataUtils.cacheMap.getOrDefault(symbol, new HashMap());
//       for (KlinesDo data : list) {
//           map.put(data.getId(), data);
//       }
//       if (map.size() > 2060) {
//           map.keySet().stream().sorted().limit(60).forEach((id) -> {
//               map.remove(id);
//           });
//       }
//       KLineDataUtils.cacheMap.put(symbol, map);
//   }


}
